package com.qf.student.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.student.entity.Classes;
import com.qf.student.entity.Student;
import com.qf.student.mapper.StudentMapper;
import com.qf.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author songfei
 * @Date 2021/10/7 18:49
 * @Version 1.0
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public void insert(Student student) {
        int i = studentMapper.insertSelective(student);
        if(i!=1){
            System.out.println("添加学员失败");
            throw new RuntimeException("添加学员失败");
        }
    }

    @Override
    public PageInfo<Student> findByclassesAndPage(Integer page, Integer rows, Integer id) {
        //1.分页
        PageHelper.startPage(page,rows);
        //2.查询
        List<Student> studentList = studentMapper.findByClassesId(id);
        //3.分装PageInfo
        PageInfo<Student> pageInfo = new PageInfo<>(studentList);
        //4.返回
        return pageInfo;
    }
}
